package com.zjitc.book.controller;

import com.zjitc.book.Dto.BookDto;
import com.zjitc.book.Dto.UserDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class UserController {

    @Autowired
    AuthenticationManager authenticationManager;
    @PostMapping("/auth/login")
    public String login(UserDto user){//Entity和DTO的区别
        System.out.println(user);

        //1.借authen来完成认证
        UsernamePasswordAuthenticationToken auth =  new UsernamePasswordAuthenticationToken(user.getUsername(),user.getPassword());
        authenticationManager.authenticate(auth);

        return "123";


    }
}
